<?php

class Comments extends Model_Abstract
{
    protected $_table_name = table_comments;
    
    public function insert( $user_id, $link_id, $content, $date_add = false )
    {
		$_modified = date( 'Y-m-d H:i:s', time() );
		if( $date_add )
			$_modified = $date_add;

		$_link = array(
			'comment_user_id' => $user_id,
			'comment_link_id' => $link_id,
			'comment_parent'  => 0,
			'comment_karma'   => 0,
			'comment_votes'   => 1,
			'comment_date'    => $_modified,
			'comment_content' => $content,
			'comment_status'  => 'published',
			'comment_randkey' => rand(1000000,100000000)
		);

		$fields = $this->_paramsToString( $_link );

		$sql = "INSERT INTO " . table_comments . " SET " . $fields;
		$this->_db->get_results($sql);

		$_id = $this->_getLastInsertId();

		return $_id;
    }
    
    public function update( $comment_id, $user_id = false, $link_id = false, $content = false, $date_add = false )
    {
		$_modified = date( 'Y-m-d H:i:s', time() );
		if( $date_add )
			$_modified = $date_add;

		$_link = array(
			'comment_user_id' => $user_id,
			'comment_link_id' => $link_id,
			'comment_parent'  => 0,
			'comment_karma'   => 0,
			'comment_votes'   => 1,
			'comment_date'    => $_modified,
			'comment_content' => $content,
			'comment_status'  => 'published',
			'comment_randkey' => rand(1000000,100000000)
		);

		$fields = $this->_paramsToString( $_link );

		$sql = "UPDATE " . table_comments . " SET " . $fields . " WHERE id=" . $comment_id;
		$this->_db->get_results($sql);

		return $comment_id;
    }

}